/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func constructMaximumBinaryTree(nums []int) *TreeNode {
    if len(nums) < 1 {
        return nil    
    }
    i, maxN := max(nums)
    root := &TreeNode{
        Val: maxN,
        Left: constructMaximumBinaryTree(nums[:i]),
        Right: constructMaximumBinaryTree(nums[i+1:]),
    }
    return root
}

func max(nums []int) (index, max int) {
    index = -1
    max = int(math.Inf(-1))
    for i, v := range nums{
        if v > max {
            max = v
            index = i
        }
    }
    return index, max
}